import request from './request'

// 获取仪表盘概览数据
export const getDashboardOverview = () => {
  return request({
    url: '/analytics/dashboard/overview/',
    method: 'get'
  })
}

// 获取实时数据
export const getRealtimeData = () => {
  return request({
    url: '/analytics/dashboard/realtime/',
    method: 'get'
  })
}

// 获取用户增长数据
export const getUserGrowthData = (period = '30d') => {
  return request({
    url: '/analytics/dashboard/user-growth/',
    method: 'get',
    params: { period }
  })
}

// 获取用户活跃度数据
export const getUserActivityData = (type = 'daily') => {
  return request({
    url: '/analytics/dashboard/user-activity/',
    method: 'get',
    params: { type }
  })
}

// 数据管理相关API

// 获取数据概览统计
export const getDataOverview = () => {
  return request({
    url: '/analytics/data/overview/',
    method: 'get'
  })
}

// 获取电商用户列表
export const getEcommerceUsersList = (params) => {
  return request({
    url: '/analytics/data/users/',
    method: 'get',
    params
  })
}

// 批量删除电商用户
export const deleteEcommerceUsers = (userIds) => {
  return request({
    url: '/analytics/data/users/delete/',
    method: 'delete',
    data: { user_ids: userIds }
  })
}

// 导出电商用户数据
export const exportEcommerceUsers = (params) => {
  return request({
    url: '/analytics/data/users/export/',
    method: 'get',
    params,
    responseType: 'blob'
  })
}

// 添加电商用户
export const addEcommerceUser = (data) => {
  return request({
    url: '/analytics/data/users/add/',
    method: 'post',
    data
  })
}

// 更新电商用户
export const updateEcommerceUser = (userId, data) => {
  return request({
    url: `/analytics/data/users/update/${userId}/`,
    method: 'put',
    data
  })
}

// 获取用户RFM分析
export const getUserRfmAnalysis = (userId) => {
  return request({
    url: `/analytics/data/users/rfm/${userId}/`,
    method: 'get'
  })
}

// 导入电商用户数据
export const importEcommerceUsers = (file) => {
  const formData = new FormData()
  formData.append('file', file)

  return request({
    url: '/analytics/data/users/import/',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}
